package com.example.module.Common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName BaseResponse
 * @Description 类注释
 * @Author 开发者
 * @Date 2023-05-09 16:58
 */
@Data
public class BaseResponse<T> {
    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

    private Map map = new HashMap(); //动态数据

    public static <T> BaseResponse<T> success(T object) {
        BaseResponse<T> r = new BaseResponse<T>();
        r.data = object;
        r.code = 1;
        return r;
    }

    public static <T> BaseResponse<T> error(String msg) {
        BaseResponse r = new BaseResponse();
        r.msg = msg;
        r.code = 0;
        return r;
    }

    public BaseResponse<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }
}
